<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body></body>
  <script>
    var arr = [1, [2, [3, 4]]];
    function flatten(arr) {
      return arr.reduce(function (prev, next) {
        //   初始值(前一个值)拼接当前值，如果是数组那么就递归调用，否则把值给prev进行拼接
        return prev.concat(Array.isArray(next) ? flatten(next) : next);
      }, []);
    }
    console.log(flatten(arr));
  </script>
</html>
